﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Exact_Extension
{
    public partial class MsgPayment : DevExpress.XtraEditors.XtraForm
    {
        ExactDataContext DS;
        ISHCMC_Invoice Inv;
         IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
        public MsgPayment()
        {
            InitializeComponent();
        }
        public MsgPayment(ISHCMC_Invoice _Inv, ExactDataContext _DS)
        {
            InitializeComponent();
            DS = _DS;
            Inv = _Inv;
            this.txtInvoiceHeaderNo.Text = Inv.ProformaInvoiceNo;
            this.txtInvoiceNo.Text = Inv.InvoiceNo;
            this.txtStudentID.Text = Inv.StudentID;
            this.cbxPaymentType.SelectedIndex = 0;
            this.dateEdit_PaymentDate.EditValue = DateTime.Now;
            
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                decimal Amount=0;
                if (this.txtPaymentAmount.Text.Length > 0)
                {
                    Amount = Convert.ToDecimal(this.txtPaymentAmount.Text);
                }
                else
                {
                    MessageBox.Show("Please input payment amount!!!");
                }
                 ISHCMC_InvoicePayment InvP = new ISHCMC_InvoicePayment()
                 {
                     InvoiceHeaderID = Inv.InvoiceHeaderID,
                     InvoiceNo = Inv.InvoiceNo,

                     PaidAmount = Amount,
                     PaymentType = this.cbxPaymentType.Text,
                     PaymentDate = Convert.ToDateTime(this.dateEdit_PaymentDate.EditValue, culture),
                     ReferenceNo = this.txtReference.Text,
                     StudentID = Inv.StudentID,
                     ItemCode = Inv.Itemcode,
                     Syscreated = DateTime.Now,
                     Sysmodified = DateTime.Now,
                     Syscreator = Environment.UserName,
                     Sysmodifier = Environment.UserName


                 };
                 DS.ISHCMC_InvoicePayments.InsertOnSubmit(InvP);
                 DS.SubmitChanges();
                 this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                this.DialogResult = DialogResult.No;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}